package com.study.composite.demo.transparent;

import java.util.ArrayList;
import java.util.List;

public class CoursePackage extends CourseComponent {

    private List<CourseComponent> items;

    private String name;
    private int level;

    public CoursePackage(String name, int level) {
        this.name = name;
        this.level = level;
        items = new ArrayList<>();
    }

    @Override
    protected void addChild(CourseComponent component) {
        items.add(component);
    }

    @Override
    protected void removeChild(CourseComponent component) {
        items.remove(component);
    }

    @Override
    protected CourseComponent getChild(int index) {
        return items.get(index);
    }

    @Override
    protected String getName() {
        return this.name;
    }

    @Override
    protected void print() {
        System.out.println(this.name);
        for (CourseComponent c:items) {
            for (int i = 0; i < this.level; i++) {
                System.out.print("    ");
            }
            System.out.print("+-");
            c.print();
        }
    }
}
